import store from "@/store"
/**
 * 权限判断
 * @param {*} app 
 */

// 超级管理员权限标识
const all_permission = '*:*:*'

export default {
    inserted(el, binding) {
        const { value } = binding
        
        const permissions = store.state.Permissions
    
        if (value && value instanceof Array && value.length > 0) {
            const permissionFlag = value
    
            const hasPermissions = permissions.some((permission) => {
                return all_permission === permission || permissionFlag.includes(permission)
            })
            if (!hasPermissions) {
                el.parentNode && el.parentNode.removeChild(el)
            }
        } else {
            throw new Error('permission.hasPermission')
        }
    }
}